local Lua__zmtx = fk.CreateSkill {

  name = "Lua__zmtx",

}

Fk:loadTranslationTable{
    
    ["Lua__zmtx"] = "流星赶月",
    ["$Lua__zmtx1"] = "朝面追形!",
    ["@@Lua__zmtx"] = "连招→<font color='red'>日字冲拳</font>",
    [":Lua__zmtx"] = "一名角色的准备阶段或你武将牌翻回正面后，你可以与一名除你以外的角色交换位置，然后你对相邻的角色各使用一张【杀】，若你的上下家为同一名角色，弃置其两张牌。",
    ["#zmtx-target"] = "朝面追形：选择一名其他角色与其交换位置",
}

Lua__zmtx:addEffect(fk.EventPhaseStart, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(Lua__zmtx.name) then return false end
        return target.phase == Player.Start
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:askToChoosePlayers(player, {
            targets = room:getOtherPlayers(player),
            min_num = 1,
            max_num = 1,
            prompt = "#zmtx-target",
            skill_name = Lua__zmtx.name,
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self, {target = to[1]})
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).target
        room:setPlayerMark(player, "@@Lua__zmtx", 1)
        -- 交换位置
        room:swapSeat(player, to)
        -- 对相邻角色使用杀
        local targets = {}
        for _, p in ipairs(room:getAlivePlayers()) do
            if player:getNextAlive() == p or p:getNextAlive() == player and not player:isProhibited(p, Fk:cloneCard("slash")) then
                table.insert(targets, p)
            end
        end
        for _, p in ipairs(targets) do
           room:useVirtualCard("slash", nil, player, p, Lua__zmtx.name)
        end
        -- 检查上下家是否为同一人
        local next_player = player:getNextAlive()
        local prev_player = player:getLastAlive()
        if next_player == prev_player and not next_player:isNude() then
            local card = room:askToChooseCards(player, {
                min = 2,
                max = 2,
                target = next_player,
                flag = "he",
                skill_name = Lua__zmtx.name,
            })
            room:throwCard({card}, Lua__zmtx.name, next_player, player)
        end
    end,
})
Lua__zmtx:addEffect(fk.TurnedOver, {
  name = "Lua__zmtx",
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(Lua__zmtx.name) and target == player and player.faceup
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:askToChoosePlayers(player, {
            targets = room:getOtherPlayers(player),
            min_num = 1,
            max_num = 1,
            prompt = "#zmtx-target",
            skill_name = Lua__zmtx.name,
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self, {target = to[1]})
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
         local room = player.room
        local to = event:getCostData(self).target
        room:setPlayerMark(player, "@@Lua__zmtx", 1)
        -- 交换位置
        room:swapSeat(player, to)
        -- 对相邻角色使用杀
        local targets = {}
        for _, p in ipairs(room:getAlivePlayers()) do
            if player:getNextAlive() == p or p:getNextAlive() == player and not player:isProhibited(p, Fk:cloneCard("slash")) then
                table.insert(targets, p)
            end
        end
        for _, p in ipairs(targets) do
           room:useVirtualCard("slash", nil, player, p, Lua__zmtx.name)
        end
        -- 检查上下家是否为同一人
        local next_player = player:getNextAlive()
        local prev_player = player:getLastAlive()
        if next_player == prev_player and not next_player:isNude() then
            local card = room:askToChooseCards(player, {
                min = 2,
                max = 2,
                target = next_player,
                flag = "he",
                skill_name = Lua__zmtx.name,
            })
            room:throwCard({card}, Lua__zmtx.name, next_player, player)
        end
    end,
})

return Lua__zmtx